
package per.jdz.circuitbreaker.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import per.jdz.circuitbreaker.CircuitBreakerBeanPostProcessor;
import per.jdz.circuitbreaker.CircuitBreakerController;
import per.jdz.circuitbreaker.ICircuitBreakerController;
import per.jdz.circuitbreaker.alert.DefaultAlert;

@Configuration
public class CircuitBreakerConfig {

    @Bean
    public CircuitBreakerProperties circuitBreakerProperties() {
        return new CircuitBreakerProperties();
    }

    @Bean("defaultAlert")
    public DefaultAlert alertService() {
        return new DefaultAlert();
    }

    @Bean
    @ConditionalOnMissingBean(CircuitBreakerController.class)
    public ICircuitBreakerController iCircuitBreakerController(CircuitBreakerProperties circuitBreakerProperties) {
        return new CircuitBreakerController(circuitBreakerProperties);
    }

    @Bean
    public CircuitBreakerBeanPostProcessor circuitBreakerBeanPostProcessor(
            ICircuitBreakerController iCircuitBreakerController) {
        return new CircuitBreakerBeanPostProcessor(iCircuitBreakerController);
    }
}